package cn.cupk.logsystem.log.strategypattren;

import cn.cupk.logsystem.log.LogRecord;
import cn.cupk.logsystem.log.strategypattren.Formatter;

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class XmlFormatter extends Formatter {
    @Override
    public String format(LogRecord record) {
        ZonedDateTime zdt = ZonedDateTime.ofInstant(record.getInstant(), ZoneId.systemDefault());
        return String.format(
                "<log>\n" +
                "   <date>%s</date>\n" +
                "   <logger>%s</logger>\n" +
                "   <level>%s</level>\n" +
                "   <message>%s</message>\n" +
                "</log>\n",
                zdt,
                record.getLoggerName(),
                record.getLevel(),
                record.getMessage()
        );
    }
}
